package com.yanqu.road.server.pb;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.game.PageantBeautyDetail;
import com.yanqu.road.entity.activity.game.PageantDetail;
import com.yanqu.road.entity.activity.game.config.BeautyConfig;
import com.yanqu.road.entity.activity.game.config.GoodsConfig;
import com.yanqu.road.entity.player.UserPageantData;
import com.yanqu.road.pb.pageant.PageantProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.activity.GamePageantMgr;

import java.util.List;

public class PageantPb {

    public static PageantProto.PageantActivityDetailMsg.Builder parsePageantActivityMsg(String language, ActivityInfo activityInfo, UserPageantData pageantData, GoodsConfig config, List<BeautyConfig> beautyConfigs) {
        //返回所有信息
        PageantProto.PageantActivityDetailMsg.Builder msg = PageantProto.PageantActivityDetailMsg.newBuilder();
        msg.setRet(0);
        //活动信息
        PageantProto.PageantActivityInfoMsg.Builder activityInfoMsg = PageantProto.PageantActivityInfoMsg.newBuilder();
        activityInfoMsg.setActivityId(activityInfo.getActivityId());
        activityInfoMsg.setActivityName(ServerLanguageMgr.getContent(activityInfo.getActivityName(), language));
        activityInfoMsg.setDescription(ServerLanguageMgr.getContent(activityInfo.getActivityDesc(), language));
        activityInfoMsg.setBeginShowTime(activityInfo.getBeginShowTime());
        activityInfoMsg.setEndShowTime(activityInfo.getEndShowTime());
        activityInfoMsg.setBeginTime(activityInfo.getBeginTime());
        activityInfoMsg.setEndTime(activityInfo.getEndTime());
        activityInfoMsg.setIcon(activityInfo.getIcon());
        activityInfoMsg.setServerList(activityInfo.getServerListStr());
        msg.setActivityInfo(activityInfoMsg);

        msg.setEntity(parsePageantBaseRespMsg(pageantData));
        //上次次刷新时间
        long oldRefreshTime = pageantData.getStrengthTime();
        msg.setLastStrengthTime(oldRefreshTime / 1000);

        //道具id列表
        PageantProto.PageantPropsMsg.Builder prop1 = PageantProto.PageantPropsMsg.newBuilder();
        prop1.setType(1);
        prop1.setId(config.getPageantRearrange());
        msg.addProps(prop1);
        PageantProto.PageantPropsMsg.Builder prop2 = PageantProto.PageantPropsMsg.newBuilder();
        prop2.setType(2);
        prop2.setId(config.getPageantMurder());
        msg.addProps(prop2);
        PageantProto.PageantPropsMsg.Builder prop3 = PageantProto.PageantPropsMsg.newBuilder();
        prop3.setType(3);
        prop3.setId(config.getPageantMoneyId());
        msg.addProps(prop3);
        PageantProto.PageantPropsMsg.Builder prop4 = PageantProto.PageantPropsMsg.newBuilder();
        prop4.setType(4);
        prop4.setId(config.getRestoreStrength());
        msg.addProps(prop4);
        msg.setMaxStrength(GamePageantMgr.getStrengthConfig().getMaxStrength());//最大体力
        msg.setIntervalTime(GamePageantMgr.getStrengthConfig().getSecends());
        msg.setRestoreStrength(GamePageantMgr.getStrengthConfig().getAddStrength());//刷新添加体力数
        //图鉴
        PageantProto.PageantPictureMsg.Builder beauty = PageantProto.PageantPictureMsg.newBuilder();
        for (BeautyConfig beautyConfig : beautyConfigs) {
            beauty.setLevel(beautyConfig.getLevel());
            beauty.setBeautyName(beautyConfig.getBeautyName());
            beauty.setBeautyDesc(beautyConfig.getBeautyDesc());
            beauty.setIntimate(beautyConfig.getIntimate());
            beauty.setFate(beautyConfig.getFate());
            beauty.setScore(beautyConfig.getScore());
            beauty.setMoney(beautyConfig.getMoney());
            msg.addPictures(beauty);
        }
        return msg;
    }


    public static PageantProto.PageantRespBaseDataEntity.Builder parsePageantBaseRespMsg(UserPageantData pageantData) {
        PageantProto.PageantRespBaseDataEntity.Builder builder = PageantProto.PageantRespBaseDataEntity.newBuilder();
        builder.setBeautyId(pageantData.getBeautyId());
        builder.setScore(pageantData.getScore());
        builder.setHighScore(pageantData.getSingleHighScore());
        builder.setStrength(pageantData.getPhysicalStrength());
        builder.setTodayGetMoney(pageantData.getTodayGetMoney());
        //最高等级
        String lockBeauty = pageantData.getLockBeauty();
        List<PageantBeautyDetail> details = JSONObject.parseArray(lockBeauty, PageantBeautyDetail.class);
        int highLevel = 1;
        for(PageantBeautyDetail detail:details){
            if(detail.isFirstShow()){
                if(detail.getBeautyLevel()>highLevel){
                    highLevel = detail.getBeautyLevel();
                }
            }
        }
        if(highLevel==11) {
            builder.setHighLevel(10);
        }else {
            builder.setHighLevel(highLevel);
        }
        //填充格子
        String paintStr = pageantData.getPaint();
        List<PageantDetail> paintArray = JSONObject.parseArray(paintStr, PageantDetail.class);
        if (null != paintArray && paintArray.size() > 0) {
            for (PageantDetail jPaint : paintArray) {
                PageantProto.PageantPaintMsg.Builder paint = PageantProto.PageantPaintMsg.newBuilder();
                paint.setValue(jPaint.getValue());
                if (0 != jPaint.getGiftBox()) {
                    paint.setGiftBox(jPaint.getGiftBox());
                }
                paint.setChest(jPaint.getChest());
                builder.addPaint(paint);
            }
        }
        return builder;
    }



}
